package com.buffer.agent.tool;


import org.springframework.stereotype.Component;

import java.io.File;
import java.nio.file.Files;

@Component
public class FileReaderTool implements AgentTool {
    @Override
    public ToolType getType() {
        return ToolType.FILE_READER;
    }
    
    @Override
    public ToolResult execute(String filePath) {
        try {
            // 参数校验
            if (filePath == null || filePath.trim().isEmpty()) {
                return new ToolResult(false, "错误：文件路径不能为空");
            }
            
            File file = new File(filePath);
            if (!file.exists()) {
                return new ToolResult(false, "错误：文件不存在 -> " + filePath);
            }
            if (!file.isFile()) {
                return new ToolResult(false, "错误：不是有效文件 -> " + filePath);
            }
            
            // 读取文本文件内容
            String content = Files.readString(file.toPath());
            return new ToolResult(true, "文件内容：\n" + content);
        } catch (Exception e) {
            return new ToolResult(false, "读取失败：" + e.getMessage());
        }
    }
}